TRANSFORM=xsltproc --nonet
DOCUMENT_NAME=Dive_Into_Pyton_3_Russian

all: html pdf wiki

html:
	[ -e out-html ] || mkdir out-html
	cp drivers/html.css out-html
	$(TRANSFORM) drivers/pre.xsl index.xml |\
	$(TRANSFORM) drivers/html.xsl -

clean-html:
	rm -rf out-html

pdf:
	[ -e out-pdf ] || mkdir out-pdf
	$(TRANSFORM) drivers/pre.xsl index.xml |\
	dblatex \
		--backend=xetex \
		--output="out-pdf/$(DOCUMENT_NAME).pdf" \
		--style=db2latex \
		--texstyle=drivers/tex.sty \
		--xsl-user=drivers/tex.xsl \
		-

clean-pdf:
	rm -rf out-pdf

wiki:
	[ -e out-wiki ] || mkdir out-wiki
	# we use empty transformation to make xsltproc unite all the source file in one XML document
	$(TRANSFORM) drivers/empty.xsl index.xml |\
	python3 drivers/wikisource.py - \
		--output-directory=out-wiki

clean-wiki:
	rm -rf out-wiki

clean: clean-html clean-pdf clean-wiki
